<template>
    <div class="news">

        <el-row>
            <el-col>
                <span style="float: left">您的位置：留学攻略</span>
            </el-col>
        </el-row>

        <el-row :gutter="20">
            <!--            左边-->
            <el-col :span="16">
                <!--                轮播图-->
                <el-row>
                    <el-carousel indicator-position="outside" height="600px">
                        <el-carousel-item v-for="item in img_list" :key="item">
                            <!--                            <h3>{{ item }}</h3>-->
                            <img :src="item">
                        </el-carousel-item>
                    </el-carousel>
                </el-row>
                <!--                留学选择-->
                <el-row>
                    <el-col :span="8">
                        <el-row><img src="https://static.jiemo.net/proc/News/Public/images/icon-lc1_120ad5f4.png">
                        </el-row>
                        <el-row><span>STEP1 留学选择</span>
                        </el-row>
                        <el-row>
                            <el-button type="primary">留学费用</el-button>
                            <el-button type="primary">留学选校</el-button>
                        </el-row>

                    </el-col>
                    <el-col :span="8">
                        <el-row>
                            <img src="https://static.jiemo.net/proc/News/Public/images/icon-lc2_5f6b3268.png">
                        </el-row>
                        <el-row>
                            <span>STEP2 申请准备</span>
                        </el-row>

                        <el-row>
                            <el-button type="primary">留学申请</el-button>
                            <el-button type="primary">留学考试</el-button>
                        </el-row>

                    </el-col>
                    <el-col :span="8">
                        <el-row><img src="https://static.jiemo.net/proc/News/Public/images/icon-lc3_35f0795e.png">
                        </el-row>
                        <el-row><span>STEP3 留学行前</span>
                        </el-row>
                        <el-row>
                            <el-button type="primary">签证申请</el-button>
                            <el-button type="primary">行前准备</el-button>
                        </el-row>


                    </el-col>
                </el-row>
            </el-col>
            <!--            右边-->
            <el-col :span="8">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>留学新闻</span>
                        <el-button style="float: right; padding: 3px 0" type="text">更多</el-button>
                    </div>
                    <div v-for="o in 4" :key="o" class="text item">
                        {{'列表内容 ' + o }}
                    </div>
                </el-card>
            </el-col>
        </el-row>

    </div>
</template>

<script>
    export default {
        name: "news",

        data() {
            return {
                loading: true,
                newsList: [],
                img_list: [require("../assets/img/player1.png"), require("../assets/img/player2.png"), require("../assets/img/player3.png")],
                newstype: 1
            };
        },
        methods: {
            loadData() {
                this.loading = true;
                this.$http
                    .get(`News?type=${this.newstype}&num=6`)
                    .then(response => {
                        //console.log(response);
                        this.newsList = response.data;
                        this.loading = false;
                        //window.console.log(this.newsList);
                    })
                    .catch(function (error) {
                        window.console.log(error);
                    });
            },
            imgPlayer() {
                // index：索引， len：长度
                var index = 0, len;
                // 类似获取一个元素数组
                var imgBox = document.getElementsByClassName("img-slide");
                len = imgBox.length;
                imgBox[index].style.display = 'block';

                // 逻辑控制函数
                function slideShow() {
                    index++;
                    // 防止数组溢出
                    if (index >= len) index = 0;
                    // 遍历每一个元素
                    for (var i = 0; i < len; i++) {
                        imgBox[i].style.display = 'none';
                    }
                    // 每次只有一张图片显示
                    imgBox[index].style.display = 'block';
                }

                // 定时器，间隔3s切换图片
                setInterval(slideShow, 3000);
            }
        },
        mounted() {
            this.imgPlayer();
            this.loadData();

        },
        watch: {
            newstype(type) {
                window.console.log(type);
                this.loadData();
            }
        }
    };
</script>

<style lang="scss" scoped>
    .news {
        width: 1800px;
        text-align: center;
        margin: 0 auto;
    }

    .el-row {
        margin-bottom: 20px;
        background-color: #f9fafc;

        &:last-child {
            margin-bottom: 0;
        }
    }

    .el-carousel__item img {
        width: 100%;
        height: 100%;
    }


    .row {
        width: 100%;
    }

    .img-slide {
        width: 100%;
    }

    .news-index-process .process-area {
        margin: 20px 0 30px;
        border-right: 1px solid #ddd;
    }

    .news-index-process .process-area span {
        display: block;
        text-align: center;
        overflow: hidden;
    }

    .box-card {
        height: 600px;
    }
</style>